package com.api.gbhg.heyulei.service.impl;

import com.api.gbhg.heyulei.api.AccountingStatusApi;
import com.api.gbhg.heyulei.dao.AccountingStatusDao;
import com.api.gbhg.heyulei.dao.ReimbursementQueryDao;
import com.api.gbhg.heyulei.dao.impl.AccountingStatusDaoImpl;
import com.api.gbhg.heyulei.dao.impl.ReimbursementQueryDaoImpl;
import com.api.gbhg.heyulei.service.AccountingStatusService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 修改报销会计审核状态实现类
 *
 * @author hyl
 * @version 1.0
 * @date 2021/5/8 15:46
 */
public class AccountingStatusServiceImpl implements AccountingStatusService {

    private ReimbursementQueryDao queryDao = new ReimbursementQueryDaoImpl();

    private AccountingStatusDao statusDao = new AccountingStatusDaoImpl();

    private Logger log = LoggerFactory.getLogger(AccountingStatusServiceImpl.class);

    /**
     * 根据requestId修改状态
     * @param param requestId
     */
    @Override
    public boolean updateAccountingStatus(Map<String,Object> param) throws Exception {
        String requestId = param.get("requestid").toString();
        //获取状态值
        String status = param.get("status").toString();
        boolean flag = false;
        try {
            //根据requestId查询表名
            String tableName = queryDao.tableName(requestId);
            log.info("流程表名:{}", tableName);
            //根据表名和requestID修改状态
            flag = statusDao.updateAccountingStatus(tableName, requestId,status);
        } catch (Exception e) {
            throw new Exception("修改报销会计审核状态失败，requestID: " + requestId);
        }
        return flag;
    }
}
